package com.rz.htk.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rz.htk.finance.entity.ExchangeRate;
import com.rz.htk.finance.mapper.ExchangeRateMapper;
import com.rz.htk.finance.service.IExchangeRateService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ExchangeRateServiceImpl
 * @Description 汇率service实现类
 * @Author maweiyue
 * @Date 2019/8/19 10:37
 */
@Service
public class ExchangeRateServiceImpl extends ServiceImpl<ExchangeRateMapper, ExchangeRate> implements IExchangeRateService {
    @Override
    public IPage<ExchangeRate> getPage(ExchangeRate product) {
        QueryWrapper<ExchangeRate> wrapper = new QueryWrapper();
        wrapper.eq("del_flag",0);
        if (StringUtils.isNotEmpty(product.getEname())) {
            wrapper.like("ename", product.getEname());
        }
        if (StringUtils.isNotEmpty(product.getName())) {
            wrapper.like("name", product.getName());
        }

        Page<ExchangeRate> page = new Page<>(product.getPageNo(), product.getPageSize());
        IPage<ExchangeRate> desktopIPage = page(page, wrapper);
        return desktopIPage;
    }

    public ExchangeRate getByKey(String key){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("ename", key);
        List<ExchangeRate> list = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}
